<!DOCTYPE html>
<html class="x-admin-sm">

<!-- 保购编辑页面 -->

<head>
    <meta charset="UTF-8">
    <title>保购编辑页面</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
        content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
    <link rel="stylesheet" href="./css/font.css">
    <link rel="stylesheet" href="./css/xadmin.css">
    <link href="css/newStyle.css" rel="stylesheet">
    <!-- 弹窗轻提示 -->
    <link href="css/plugins/sweetalert/sweetalert.css" rel="stylesheet">
    <script src="js/plugins/sweetalert/sweetalert.min.js"></script>
    <!-- 引入jq -->
    <script src="https://cdn.bootcss.com/jquery/3.4.0/jquery.min.js"></script>
    <script src="./lib/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="./js/xadmin.js"></script>
    <script type="text/javascript" src="./js/common.js"></script>
    <!-- <script type="text/javascript" src="./js/domain.js"></script> -->

    <!--[if lt IE 9]>
          <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
          <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
        <![endif]-->
    <style>
        .sexCont {
            margin-left: 0;
        }
        .none {
            display: none;
        }
        .layui-btn {
            font-size: 13px !important;
            width: 180px !important;
            height: 35px !important;
            border-radius: 4px !important;
            background-color: rgba(26, 188, 156, 1) !important;
            color: #fff !important;
            margin: 40px auto;
        }
        .layui-form-switch {
            position: relative;
            top: 6px;
        }
    </style>
</head>

<body>
    <div class="layui-fluid">
        <div
            style="color: #666; font-size: 12px; padding-left: 10px; height: 40px;line-height: 40px;background-color: #eee;width: 98.%;border: 1px solid #ccc;">
            编辑资料</div>
        <div class="layui-row" style="border: 1px #ccc solid; border-top: none;">
            <form class="layui-form" style="padding-left: 150px;">
                <!-- 手机号码 -->
                <div class="layui-form-item" style="padding-top: 35px;">
                    <label for="L_email" class="layui-form-label">手机号码：</label>
                    <div class="layui-input-inline">
                        <input type="text" id="L_email" name="phone" required="" autocomplete="off"
                            class="layui-input user_phone">
                    </div>
                    <div class="layui-form-mid layui-word-aux"></div>
                </div>

                <div class="layui-form-item">
                    <label for="L_username1" class="layui-form-label">会员等级：</label>
                    <input type="number" id="L_username1" name="sale_score" required="" autocomplete="off"
                        class="layui-input-inline user_star layui-input" disabled=''>
                </div>

                <div class="layui-form-item">
                    <label for="L_username2" class="layui-form-label">性别：</label>
                    <div class="layui-input-inline">
                        <div class="layui-input-block sexCont">
                            <input type="radio" name="sex" value="0" title="保密" class="mi">
                            <input type="radio" name="sex" value="1" title="男" class="nan">
                            <input type="radio" name="sex" value="2" title="女" class="nv">
                        </div>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label for="L_username3" class="layui-form-label">生日：</label>
                    <div class="layui-input-inline">
                        <input name="birthday" type="text" class="layui-input  user_day" id="editTim"
                            placeholder="请选择时间">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label for="L_username4" class="layui-form-label">城市：</label>
                    <div class="layui-input-inline">
                        <select name="province_id" class="user_city" id="productBrand" lay-filter="demo">
                            <option value="">请输入省份</option>
                            <!-- <option value="浙江" selected="">浙江省</option>
                            <option value="江西">江西省</option>
                            <option value="福建">福建省</option> -->
                        </select>
                    </div>
                    <div class="layui-input-inline">
                        <select name="city_id" class="" id="user_city">
                            <option value="">请输入市</option>
                            <!-- <option value="杭州">杭州</option>
                            <option value="宁波">宁波</option>
                            <option value="温州">温州</option>
                            <option value="温州">台州</option>
                            <option value="温州">绍兴</option> -->
                        </select>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label for="L_username5" class="layui-form-label">职业：</label>
                    <div class="layui-input-inline">
                        <input type="text" id="L_username5" name="occupation" required="" lay-verify="nickname"
                            autocomplete="off" class="layui-input nickname">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label for="L_username6" class="layui-form-label">个性签名：</label>
                    <div class="layui-input-inline">
                        <textarea name="personalSignature" id="L_username6" cols="50" rows="8"
                            class="personal_signature"></textarea>
                    </div>
                </div>

                <div class="layui-form-item">
                    <label for="L_pass" class="layui-form-label">密码：</label>
                    <div class="layui-input-inline">
                        <input type="password" id="L_pass" name="pass" required="" lay-verify="pass" autocomplete="off"
                            class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label for="L_repass" class="layui-form-label">确认密码：</label>
                    <div class="layui-input-inline">
                        <input type="password" id="L_repass" name="repass" required="" lay-verify="repass"
                            autocomplete="off" class="layui-input">
                    </div>
                </div>

                <div class="layui-form-item">
                    <label for="L_pass" class="layui-form-label">启用状态：</label>
                    <div class="layui-input-inline">
                        <input type="checkbox" name="status" lay-skin="switch" lay-filter="switchTest" title="开关"
                            class="status" id="newGoods" >
                    </div>
                </div>
                <div class="layui-form-item edit_btn">
                    <label for="L_repass" class="layui-form-label"></label>
                    <button class="layui-btn " lay-filter="add" lay-submit="" type="button">提交</button>
                </div>
            </form>
        </div>
    </div>
    <script>
        layui.use(['form', 'laydate', 'layer'],
            function () {
                $ = layui.jquery;
                var form = layui.form,
                    laydate = layui.laydate,
                    layer = layui.layer;

                laydate.render({
                    elem: '#editTim'
                });

                //自定义验证规则
                form.verify({
                    nikename: function (value) {
                        if (value.length < 5) {
                            return '昵称至少得5个字符啊';
                        }
                    },
                    pass: [/(.+){6,12}$/, '密码必须6到12位'],
                    repass: function (value) {
                        if ($('#L_pass').val() != $('#L_repass').val()) {
                            return '两次密码不一致';
                        }
                    }
                });
                // 获取页面跳转过来参数
                function getUrlParam(name) {
                    var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)"); //构造一个含有目标参数的正则表达式对象
                    var r = window.location.search.substr(1).match(reg);  //匹配目标参数
                    if (r != null) return unescape(r[2]); return null; //返回参数值
                }
                var buyMid = getUrlParam("id"); //当前保购id
                // console.log(buyMid, '查看id')
                //省市下拉的数据渲染
                $.ajax({
                    type: 'get',
                    url: urls + 'regions/regionsList',
                    headers: {
                        'X-Access-Token': JSON.parse(sessionStorage.getItem("user_message")).token,
                    },
                    data: {
                        type: 1
                    },
                    success: function (res) {
                        // 进行下拉列表的渲染
                        CheckLogout(res); //检查是否登陆过
                        if (res.code == 0) {
                            for (var i = 0; i < res.data.length; i++) {
                                $("#productBrand").append("<option value=\"" + res.data[i].id + "\">" + res.data[i].name + "</option>");
                            }
                            //重新渲染
                            layui.form.render("select");
                        } else {
                            layer.msg(res.message);
                        }
                    }
                })
                //  监听下拉框事件

                // 监听一级下拉框
                form.on('select(demo)', function (data) {
                    // var message = $("select[name=quiz1").val();
                    //  console.log(message)
                    // 市级列表的渲染
                    $.ajax({
                        type: 'get',
                        url: urls + 'regions/regionsList',
                        headers: {
                            'X-Access-Token': JSON.parse(sessionStorage.getItem("user_message")).token,
                        },
                        data: {
                            // token: token,
                            type: 2,
                            parentId: data.value
                        },
                        success: function (res) {
                            CheckLogout(res); //检查是否登陆过
                            // console.log(res,'省级')
                            // 进行下拉列表的渲染
                            if (res.code == 0) {
                                for (var i = 0; i < res.data.length; i++) {
                                    $("#user_city").append("<option value=\"" + res.data[i].id + "\">" + res.data[i].name + "</option>");
                                }
                                //重新渲染
                                layui.form.render("select");
                            } else {
                                layer.msg(res.message);
                            }
                        }
                    })
                });
                // 编辑页面的数据回写
                Showload();
                $.ajax({
                    type: 'post',
                    url: urls + 'sales/getSalesDetails',
                    headers: {
                        'X-Access-Token': JSON.parse(sessionStorage.getItem("user_message")).token,
                    },
                    data: { id: buyMid, token: token },
                    success: function (res) {
                        CheckLogout(res); //检查是否登陆过
                        if (res.code == 0) {
                            InitTime();
                            //  console.log(res,'编辑数据回写')
                            $('.user_phone').val(res.data.phone)
                            $('.user_star').val(res.data.sale)
                            // console.log(res.data.sale)
                            // if(res.data.sale == 0){
                            //     $('.user_star').val('新手')
                            // }else if(res.data.sale == 1){
                            //     $('.user_star').val('一星级')
                            // }else if(res.data.sale == 2){
                            //     $('.user_star').val('二星级')
                            // }else if(res.data.sale == 3){
                            //     $('.user_star').val('三星级')
                            // }else if(res.data.sale == 4){
                            //     $('.user_star').val('四星级')
                            // }else if(res.data.sale == 5){
                            //     $('.user_star').val('五星级')
                            // }else if(res.data.sale == 6){
                            //     $('.user_star').val('六星级')
                            // }else if(res.data.sale == 7){
                            //     $('.user_star').val('七星级')
                            // }else if(res.data.sale == 8){
                            //     $('.user_star').val('八星级')
                            // }

                            // 性别的回写
                            var radio = document.getElementsByName("sex");
                            if (res.data.sex == 0) {
                                // 保密
                                $(radio[0]).next('div').click();
                            } else if (res.data.sex == 1) {
                                //  男

                                $(radio[1]).next('div').click();
                            } else if (res.data.sex == 2) {
                                //  女
                                $(radio[2]).next('div').click();
                            }
                            $('.user_day').val(res.data.birthday)
                            form.render();
                            $('.user_city').val(res.data.province_id)
                            form.render();
                            $('.user_cities').val(res.data.city_id)
                            form.render(); //下拉重新渲染
                            $('.nickname').val(res.data.occupation)
                            $('.personal_signature').val(res.data.personal_signature)
                            $('#L_pass').val(res.data.account_password)
                            $('#L_repass').val(res.data.account_password)
                            if (res.data.status == 1) {
                                $("input[id='newGoods']").next('div').click();
                            }
                        } else {
                            TipsAlert("请求数据失败,请联系后台技术人员");
                        }
                    }
                })
                form.render();


                //监听提交
                form.on('submit(add)',
                    function (data) {
                        var message = {};
                        message.id = buyMid;
                        message.phone = data.field.phone;
                        message.sex = data.field.sex;
                        message.province_id = data.field.province_id;
                        message.city_id = data.field.city_id;
                        //  message.birthday = data.field.birthday;
                        message.occupation = data.field.occupation
                        message.personalSignature = data.field.personalSignature
                        message.accountPassword = data.field.pass;
                        message.status = data.field.status == 'on' ? 1 : 2;
                        // console.log(message, '编辑后的数据')
                        $.ajax({
                            type: 'post',
                            url: urls + 'sales/salesUpdate',
                            headers: {
                                'X-Access-Token': JSON.parse(sessionStorage.getItem("user_message")).token,
                            },
                            data: JSON.stringify(message),
                            // contentType : 'json',
                            dataType: "json",
                            contentType: 'application/json;charset=UTF-8',
                            success: function (res) {
                                CheckLogout(res); //检查是否登陆过
                                if (res.code == 0) {
                                    layer.alert("保购信息编辑成功,请返回！", {
                                        icon: 6
                                    })
                                    $('.edit_btn').css('display', 'none');
                                } else {
                                    layer.msg(res.msg)
                                }

                            }
                        })
                        return false;
                    });
            });
    </script>
    <script>
        var _hmt = _hmt || [];
        (function () {
            var hm = document.createElement("script");
            hm.src = "https://hm.baidu.com/hm.js?b393d153aeb26b46e9431fabaf0f6190";
            var s = document.getElementsByTagName("script")[0];
            s.parentNode.insertBefore(hm, s);
        })();
    </script>
</body>

</html>